User blog:Allenallenallen333/Scripting Concepts for All LEGO Games
Things to note before reading: *I'm no expert in this but I'm trying to give ideas to people on how to program some parts of the LEGO Game everyone is trying to make. *Note that the following concepts can be modified to suit your game. *This concept does not only apply to Unity, but also pretty much all the other different types of coding languages. *I will probably only talk about functions people forget to program or just don't know how to make it work. *The following how my logic on how things will work out in Single Player, not Multiplayer. Multiplayer is much more complicated. *I hope to go more in depth later on when I acutally learn how Unity functions work. But until then... here's my logic. ---- ID numbers can help you organize items in your game, whether they are weapons, clothes or bricks. Here's a list of things that need ID numbers. Weapons and Tools Hair Styles Shirts Colors Pants Types of Eyebrows Types of Mouths Types of Eyes Hats/Helmets Every brick Every suit of armor PRETTY MUCH EVERYTHING NEEDS TO HAVE AN ID The following are scripting concepts that I believe should work using my logic. It should still make sense to you even if you are not into coding. I'll be using "//" as a comments just like Unity. The comments will always to ABOVE of what is is commenting on. Note that sometimes there will be double comments meaning it is more important. I always think of coding as 2 separate parts. One part is memorization and the other is problem solving. And a little bit of typing skills but this doesn't really count. 1. The first part is knowing and memorizing the coding language itself. You must be able to recall certain functions and how to type them. This is probably the hardest part. But this is something everyone can eventually learn with time. It may take a long time for you to remember an entire coding language like JavaScript or C#, but it's worth the time. 2. The second part is knowing how to solve a problem with lines and lines of codes. For example, someone asks you to create a script that can convert meters to feet; you must be able to picture what functions and codes you will use, and how you will organize them. This needs practice, lots and lots of practice. You must be able to think of the best way to write out this script. The best way meaning it must run fast and be as short as possible. It also needs to be efficient. I'm going to provide you the second part of coding; you have to figure out the first part by yourself. Stance, Running, Jumping animations are included with Unity so I won't talk about that. Double Jump: (Not sure if applicable. Also depends on the the direction the character is jumping.) //This makes sure that you can only jump again when you are already jumping. It also avoid having infinite jumps. If jumping is true and button "space" is pressed, then play double_jump_animation and set double jump to true and set jumping to false. Attacking Animation: (You know how LEGO Universe had a three hit combo thing? This is how you can program it.) //This is the first hit combo of your three hit combo weapon. If attacking button is pressed, start attacking_animation. //We don't want the entire attack animation to deal damage. Or else you would be able to kill your enemy by raising your sword, which wouldn't make sense. During the attacking_animation when the weapon is logically going to deal damage, set attacking to true; else attacking is set to false. //This is the second hit combo of your three hit combo weapon. If attacking button is pressed during the last 0.5 second of attacking_animation, start attacking_animation_2. During the attacking_animation_2 when the weapon is logically going to deal damage, set attacking to true; else attacking is set to false. //This is the third and last hit combo of your three hit combo weapon. If attacking button is pressed during the last 0.5 second of attacking_animation, start attacking_animation_3. During the attacking_animation_3 when the weapon is logically going to deal damage, set attacking to true; else attacking is set to false. Armor Points: Variables: armor_power (This is just a random variable I thought of. It can either be true or false. If it is true, it means armor is on. If it is false, it means you have no armor on." //Simple. All of your armor points is equal to all the things you wear that can increase armor points. Total armor points = Everything the character wears that can increase armor points + Extra armor points //When you are out of armor points, this armor_power thing is now false. The armor_power is just a variable that we can keep track of whether you have armor points or not. If armor points = 0, then set armor_power to false. //When you have armor and you are being attacked, then the armor points take the damage. If armor_power is true and attacking is true, then armor points - damage dealt. Health Points: //Simple, just like the total armor points. Everything you wear that can increase armor points, you get them as a total. Total health points = Everything the character wears that can increase health points + Extra health points //When you are out of armor and you are being attacked, then your health points takes the damage. If armor_power is false and attacking is true, then health points - damage dealt. //Easy. When you are out of hearts, you die. If health points = 0, then set death to true. //This is a bit tricky. You know how in LEGO Universe you have both armor and hearts? This is the same exact thing. This allows the health points to continue taking the damage after you run out of armor. For example: You have 2 armor and 5 hearts. You took a damage of 4. Your armor has to take 2 of the damage, leaving another 2 damage. The remaining 2 damage has to be taken by the 5 hearts, so you have 3 hearts left. If armor points < damage dealt, then set armor points to 0 and health points - (damage dealt - armor points). Receiving Damage from Attacks: //This checks to see if shield is on. If it is, then the shield takes the attack. If it's not, you take the damage directly. When being attacked and shield is on, then shield absorbs the attack; else, you recieve damage. //Doesn't matter if you are running or attacking, if you somehow get hurt in the middle of something, you will still be hurt. When damage is recieved, end all animations, start hurt_animation. Restoring Armor Points: //When you restore your armor, you can restore only up to your maximum armor, no more than that. This stops your armor points from going over the limit. If restore armor is used, "if (restore armor + armor points) < or = max armor, then armor points + restore armor"; else set armor points = max armor. Restoring Health Points: //Pretty much the same as restoring armor points. No differences at all. If restore health is used, "if (restore health + health points) < or = max health, then health points + restore health"; else set health points = max health. Enemy Health Points: //Simple enough. The enemy dies when it runs out of hearts. If enemy health points = 0 then enemy dies. //Let's just say the attack you dealt to the enemy is higher than its health points, I don't want a negative value. So I just make the enemy health points equal to zero. In which case, it dies. If enemy health points < Damage dealt, then set enemy health points to 0. Hitting/Attacking: //You are attacking and there's an enemy in your weapon's range; you deal this amount of damage to the enemy's health points. //This can be a lot more complicated if you are going to allow Player vs Player (PVP) in your game. If attacking is true and enemy is within attack range, then deal this amount of damage to the targetted enemy. //This calculates the amount of damage you can deal to the enemy with that attack. The total damage dealt equals to the amount of damage a weapon can deal with which hit of combo (1, 2 or 3) multiply by someting (Like maybe twice the damage after you drink a potion) plus additional damage you can deal due to maybe an effect of your weapon Damage dealt = damage points of the weapon at what combo * Amount of extra damage (Ex: or 30 seconds, you can deal 2x damage) + Bonus damage (Ex: Wearing this helmet allows you to deal an extra 2 damage to the enemy for every attack you give) Death and Respawn: Variable: death (Whether you are dead or not. True or false.) Variable: respawn (Are you ready to respawn? True or false.) //This is to ensure that the character dies if anything happens like a bug or a glitch. If death is true, set heart points to 0 and armor points to zero and continue to respawn. //This allows a button to come up after you die saying if you want to respawn. This is a manual respawn like LEGO Universe's "Rebuild" button after you died. //You can make it so that you automatically respawns. No need for manual confirmation. If respawn is true, then GUI pops up. //Like after you press "Rebuild" you respawn to the nearest safe point. //The nearest safe point can be identified by finding the distance between all the safe points to the character. The safe point of the shortest distance is where you would respawn. If GUI is pressed then the character respawns in the nearest spawn point. Force respawn: (You know how when you get stuck in a place in LEGO Universe, you can smash yourself to get out? This is it.) //This forces the character's armor and hearts to reach 0, thus killing the character. When this GUI is pressed, set armor points to 0 and set health points to 0. ---- This should save you some time. Feel free to comment on your ideas if you actually understand my way of thinking. Sorry that it's a mess, I typed this in notepad first then I copied it here. Category:Blog posts